package simonxianyu.learn.springmybatis.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import simonxianyu.learn.springmybatis.util.DataTableInputResolver;

import java.util.List;

/**
 *
 * Created by simon on 2017/2/20.
 */
@Configuration
@EnableWebMvc
@ComponentScan(
    basePackages = "simonxianyu.learn.springmybatis.web",
    includeFilters = @ComponentScan.Filter(classes = Controller.class),
    excludeFilters = @ComponentScan.Filter(classes = Configuration.class))
public class WebContext extends WebMvcConfigurerAdapter {

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    super.addResourceHandlers(registry);
    registry.addResourceHandler("/static/**").addResourceLocations("/static/");
  }

  @Override
  public void configureViewResolvers(ViewResolverRegistry registry) {
    super.configureViewResolvers(registry);
    registry.jsp("WEB-INF/pages/",".jsp");
  }

  @Override
  public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
    super.addArgumentResolvers(argumentResolvers);
    argumentResolvers.add(new DataTableInputResolver());
  }
}
